package com.mymarkdown.app.common.lister.impl;

import com.mymarkdown.app.common.lister.WatchFile;
import com.mymarkdown.app.interfaces.ModifyWindow;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @author ：zenglun
 * @date ：Created in 2021/12/25 10:04 PM
 * @description：
 * @modified By：
 * @version: $
 */
@Slf4j
@Component
public class WatchFileImpl implements WatchFile {

    @Autowired
    @Lazy
    private ModifyWindow modifyWindow;

    @Override
    public void watch(String path, String parentPath, WatchFileType watchFileType) {
        //监听
        log.info("[WatchFileImpl]---[watch], path:{},parentPath:{},watchFileType:{}", path, parentPath, watchFileType);
        if (WatchFileType.REMOVE.equals(watchFileType)){
            //TODO 移除相应的节点
            modifyWindow.removeItemByPath(path);
        }else{
            //TODO 添加相应的节点
            modifyWindow.addTreeItemByPath(path);
        }
    }
}
